package com.dgut.crm.system.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Version;

import com.dgut.crm.common.util.enumType.MenuType;

@Entity
@Table(name="menu")
public class Menu {
	private Long id;  
	private String name;  //菜单名（对应控制器、方法名）
	private String title; //中文名
	private String url; //访问的链接
	private Integer version; //排序值
	private Long fatherId; //父节点ID（fatherId对应相应的控制器）
	private MenuType menuType; //节点类型：1:表示应用（模块）；2:表示控制器；3：表示方法
	
	private List<Role> roles = new ArrayList<Role>();
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	@Column(length=20,unique=true,nullable=false)
	public String getName() {
		return name;
	}
	
	@Column(length=30,nullable=true)
	public String getTitle() {
		return title;
	}

	@Column(length=50,nullable=false)
	public String getUrl() {
		return url;
	}
	
	@Version
	public Integer getVersion() {
		return version;
	}
	
	public Long getFatherId() {
		return fatherId;
	}

	public MenuType getType() {
		return menuType;
	}

	@ManyToMany(mappedBy="menus",fetch=FetchType.LAZY)
	public List<Role> getRoles() {
		return roles;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public void setFatherId(Long fatherId) {
		this.fatherId = fatherId;
	}

	public void setType(MenuType type) {
		this.menuType = type;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
	public Menu() {
	}

	public Menu(Long id, String name, String title, String url, Integer version, Long fatherId, MenuType menuType,
			List<Role> roles) {
		super();
		this.id = id;
		this.name = name;
		this.title = title;
		this.url = url;
		this.version = version;
		this.fatherId = fatherId;
		this.menuType = menuType;
		this.roles = roles;
	}

	@Override
	public String toString() {
		return "Menu [id=" + id + ", name=" + name + ", title=" + title + ", url=" + url + ", version=" + version
				+ ", fatherId=" + fatherId + ", menuType=" + menuType +"]";
	}
}
